<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>19.6. mimetools — Tools for parsing MIME messages &mdash; Python v2.6.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v2.6.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v2.6.2 documentation" href="../index.html" />
    <link rel="up" title="19. Internet Data Handling" href="netdata.html" />
    <link rel="next" title="19.7. mimetypes — Map filenames to MIME types" href="mimetypes.html" />
    <link rel="prev" title="19.5. mhlib — Access to MH mailboxes" href="mhlib.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="mimetypes.html" title="19.7. mimetypes — Map filenames to MIME types"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mhlib.html" title="19.5. mhlib — Access to MH mailboxes"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="netdata.html" accesskey="U">19. Internet Data Handling</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-mimetools">
<h1>19.6. <tt class="xref docutils literal"><span class="pre">mimetools</span></tt> &#8212; Tools for parsing MIME messages<a class="headerlink" href="#module-mimetools" title="Permalink to this headline">¶</a></h1>
<p>
<span class="versionmodified">Deprecated since version 2.3: </span>The <a title="Package supporting the parsing, manipulating, and generating email messages, including MIME documents." class="reference external" href="email.html#module-email"><tt class="xref docutils literal"><span class="pre">email</span></tt></a> package should be used in preference to the <tt class="xref docutils literal"><span class="pre">mimetools</span></tt>
module.  This module is present only to maintain backward compatibility, and
it has been removed in 3.x.</p>
<p id="index-414">This module defines a subclass of the <a title="Parse 2822 style mail messages. (deprecated)" class="reference external" href="rfc822.html#module-rfc822"><tt class="xref docutils literal"><span class="pre">rfc822</span></tt></a> module&#8217;s <a title="mimetools.Message" class="reference internal" href="#mimetools.Message"><tt class="xref docutils literal"><span class="pre">Message</span></tt></a>
class and a number of utility functions that are useful for the manipulation for
MIME multipart or encoded message.</p>
<p>It defines the following items:</p>
<dl class="class">
<dt id="mimetools.Message">
<em class="property">
class </em><tt class="descclassname">mimetools.</tt><tt class="descname">Message</tt><big>(</big><em>fp</em><span class="optional">[</span>, <em>seekable</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#mimetools.Message" title="Permalink to this definition">¶</a></dt>
<dd>Return a new instance of the <a title="mimetools.Message" class="reference internal" href="#mimetools.Message"><tt class="xref docutils literal"><span class="pre">Message</span></tt></a> class.  This is a subclass of the
<a title="rfc822.Message" class="reference external" href="rfc822.html#rfc822.Message"><tt class="xref docutils literal"><span class="pre">rfc822.Message</span></tt></a> class, with some additional methods (see below).  The
<em>seekable</em> argument has the same meaning as for <a title="rfc822.Message" class="reference external" href="rfc822.html#rfc822.Message"><tt class="xref docutils literal"><span class="pre">rfc822.Message</span></tt></a>.</dd></dl>

<dl class="function">
<dt id="mimetools.choose_boundary">
<tt class="descclassname">mimetools.</tt><tt class="descname">choose_boundary</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.choose_boundary" title="Permalink to this definition">¶</a></dt>
<dd>Return a unique string that has a high likelihood of being usable as a part
boundary.  The string has the form <tt class="docutils literal"><span class="pre">'hostipaddr.uid.pid.timestamp.random'</span></tt>.</dd></dl>

<dl class="function">
<dt id="mimetools.decode">
<tt class="descclassname">mimetools.</tt><tt class="descname">decode</tt><big>(</big><em>input</em>, <em>output</em>, <em>encoding</em><big>)</big><a class="headerlink" href="#mimetools.decode" title="Permalink to this definition">¶</a></dt>
<dd>Read data encoded using the allowed MIME <em>encoding</em> from open file object
<em>input</em> and write the decoded data to open file object <em>output</em>.  Valid values
for <em>encoding</em> include <tt class="docutils literal"><span class="pre">'base64'</span></tt>, <tt class="docutils literal"><span class="pre">'quoted-printable'</span></tt>, <tt class="docutils literal"><span class="pre">'uuencode'</span></tt>,
<tt class="docutils literal"><span class="pre">'x-uuencode'</span></tt>, <tt class="docutils literal"><span class="pre">'uue'</span></tt>, <tt class="docutils literal"><span class="pre">'x-uue'</span></tt>, <tt class="docutils literal"><span class="pre">'7bit'</span></tt>, and  <tt class="docutils literal"><span class="pre">'8bit'</span></tt>.  Decoding
messages encoded in <tt class="docutils literal"><span class="pre">'7bit'</span></tt> or <tt class="docutils literal"><span class="pre">'8bit'</span></tt> has no effect.  The input is simply
copied to the output.</dd></dl>

<dl class="function">
<dt id="mimetools.encode">
<tt class="descclassname">mimetools.</tt><tt class="descname">encode</tt><big>(</big><em>input</em>, <em>output</em>, <em>encoding</em><big>)</big><a class="headerlink" href="#mimetools.encode" title="Permalink to this definition">¶</a></dt>
<dd>Read data from open file object <em>input</em> and write it encoded using the allowed
MIME <em>encoding</em> to open file object <em>output</em>. Valid values for <em>encoding</em> are
the same as for <a title="mimetools.decode" class="reference internal" href="#mimetools.decode"><tt class="xref docutils literal"><span class="pre">decode()</span></tt></a>.</dd></dl>

<dl class="function">
<dt id="mimetools.copyliteral">
<tt class="descclassname">mimetools.</tt><tt class="descname">copyliteral</tt><big>(</big><em>input</em>, <em>output</em><big>)</big><a class="headerlink" href="#mimetools.copyliteral" title="Permalink to this definition">¶</a></dt>
<dd>Read lines from open file <em>input</em> until EOF and write them to open file
<em>output</em>.</dd></dl>

<dl class="function">
<dt id="mimetools.copybinary">
<tt class="descclassname">mimetools.</tt><tt class="descname">copybinary</tt><big>(</big><em>input</em>, <em>output</em><big>)</big><a class="headerlink" href="#mimetools.copybinary" title="Permalink to this definition">¶</a></dt>
<dd>Read blocks until EOF from open file <em>input</em> and write them to open file
<em>output</em>.  The block size is currently fixed at 8192.</dd></dl>

<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt>Module <a title="Package supporting the parsing, manipulating, and generating email messages, including MIME documents." class="reference external" href="email.html#module-email"><tt class="xref docutils literal"><span class="pre">email</span></tt></a></dt>
<dd>Comprehensive email handling package; supersedes the <tt class="xref docutils literal"><span class="pre">mimetools</span></tt> module.</dd>
<dt>Module <a title="Parse 2822 style mail messages. (deprecated)" class="reference external" href="rfc822.html#module-rfc822"><tt class="xref docutils literal"><span class="pre">rfc822</span></tt></a></dt>
<dd>Provides the base class for <a title="mimetools.Message" class="reference internal" href="#mimetools.Message"><tt class="xref docutils literal"><span class="pre">mimetools.Message</span></tt></a>.</dd>
<dt>Module <a title="Support for reading files which contain distinct parts, such as some MIME data. (deprecated)" class="reference external" href="multifile.html#module-multifile"><tt class="xref docutils literal"><span class="pre">multifile</span></tt></a></dt>
<dd>Support for reading files which contain distinct parts, such as MIME data.</dd>
<dt><a class="reference external" href="http://faqs.cs.uu.nl/na-dir/mail/mime-faq/.html">http://faqs.cs.uu.nl/na-dir/mail/mime-faq/.html</a></dt>
<dd>The MIME Frequently Asked Questions document.  For an overview of MIME, see the
answer to question 1.1 in Part 1 of this document.</dd>
</dl>
</div>
<div class="section" id="additional-methods-of-message-objects">
<span id="mimetools-message-objects"></span><h2>19.6.1. Additional Methods of Message Objects<a class="headerlink" href="#additional-methods-of-message-objects" title="Permalink to this headline">¶</a></h2>
<p>The <a title="mimetools.Message" class="reference internal" href="#mimetools.Message"><tt class="xref docutils literal"><span class="pre">Message</span></tt></a> class defines the following methods in addition to the
<a title="rfc822.Message" class="reference external" href="rfc822.html#rfc822.Message"><tt class="xref docutils literal"><span class="pre">rfc822.Message</span></tt></a> methods:</p>
<dl class="method">
<dt id="mimetools.Message.getplist">
<tt class="descclassname">Message.</tt><tt class="descname">getplist</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.getplist" title="Permalink to this definition">¶</a></dt>
<dd>Return the parameter list of the <em>Content-Type</em> header. This is a
list of strings.  For parameters of the form <tt class="docutils literal"><span class="pre">key=value</span></tt>, <em>key</em> is converted
to lower case but <em>value</em> is not.  For example, if the message contains the
header <tt class="docutils literal"><span class="pre">Content-type:</span> <span class="pre">text/html;</span> <span class="pre">spam=1;</span> <span class="pre">Spam=2;</span> <span class="pre">Spam</span></tt> then <a title="mimetools.Message.getplist" class="reference internal" href="#mimetools.Message.getplist"><tt class="xref docutils literal"><span class="pre">getplist()</span></tt></a>
will return the Python list <tt class="docutils literal"><span class="pre">['spam=1',</span> <span class="pre">'spam=2',</span> <span class="pre">'Spam']</span></tt>.</dd></dl>

<dl class="method">
<dt id="mimetools.Message.getparam">
<tt class="descclassname">Message.</tt><tt class="descname">getparam</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#mimetools.Message.getparam" title="Permalink to this definition">¶</a></dt>
<dd>Return the <em>value</em> of the first parameter (as returned by <a title="mimetools.Message.getplist" class="reference internal" href="#mimetools.Message.getplist"><tt class="xref docutils literal"><span class="pre">getplist()</span></tt></a>) of
the form <tt class="docutils literal"><span class="pre">name=value</span></tt> for the given <em>name</em>.  If <em>value</em> is surrounded by
quotes of the form &#8216;<tt class="docutils literal"><span class="pre">&lt;</span></tt>...<tt class="docutils literal"><span class="pre">&gt;</span></tt>&#8216; or &#8216;<tt class="docutils literal"><span class="pre">&quot;</span></tt>...<tt class="docutils literal"><span class="pre">&quot;</span></tt>&#8216;, these are removed.</dd></dl>

<dl class="method">
<dt id="mimetools.Message.getencoding">
<tt class="descclassname">Message.</tt><tt class="descname">getencoding</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.getencoding" title="Permalink to this definition">¶</a></dt>
<dd>Return the encoding specified in the <em>Content-Transfer-Encoding</em>
message header.  If no such header exists, return <tt class="docutils literal"><span class="pre">'7bit'</span></tt>.  The encoding is
converted to lower case.</dd></dl>

<dl class="method">
<dt id="mimetools.Message.gettype">
<tt class="descclassname">Message.</tt><tt class="descname">gettype</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.gettype" title="Permalink to this definition">¶</a></dt>
<dd>Return the message type (of the form <tt class="docutils literal"><span class="pre">type/subtype</span></tt>) as specified in the
<em>Content-Type</em> header.  If no such header exists, return
<tt class="docutils literal"><span class="pre">'text/plain'</span></tt>.  The type is converted to lower case.</dd></dl>

<dl class="method">
<dt id="mimetools.Message.getmaintype">
<tt class="descclassname">Message.</tt><tt class="descname">getmaintype</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.getmaintype" title="Permalink to this definition">¶</a></dt>
<dd>Return the main type as specified in the <em>Content-Type</em> header.  If
no such header exists, return <tt class="docutils literal"><span class="pre">'text'</span></tt>.  The main type is converted to lower
case.</dd></dl>

<dl class="method">
<dt id="mimetools.Message.getsubtype">
<tt class="descclassname">Message.</tt><tt class="descname">getsubtype</tt><big>(</big><big>)</big><a class="headerlink" href="#mimetools.Message.getsubtype" title="Permalink to this definition">¶</a></dt>
<dd>Return the subtype as specified in the <em>Content-Type</em> header.  If no
such header exists, return <tt class="docutils literal"><span class="pre">'plain'</span></tt>.  The subtype is converted to lower case.</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../contents.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">19.6. <tt class="docutils literal"><span class="pre">mimetools</span></tt> &#8212; Tools for parsing MIME messages</a><ul>
<li><a class="reference external" href="#additional-methods-of-message-objects">19.6.1. Additional Methods of Message Objects</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="mhlib.html"
                                  title="previous chapter">19.5. <tt class="docutils literal docutils literal docutils literal"><span class="pre">mhlib</span></tt> &#8212; Access to MH mailboxes</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="mimetypes.html"
                                  title="next chapter">19.7. <tt class="docutils literal"><span class="pre">mimetypes</span></tt> &#8212; Map filenames to MIME types</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/library/mimetools.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="mimetypes.html" title="19.7. mimetypes — Map filenames to MIME types"
             >next</a> |</li>
        <li class="right" >
          <a href="mhlib.html" title="19.5. mhlib — Access to MH mailboxes"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="netdata.html" >19. Internet Data Handling</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; <a href="../copyright.html">Copyright</a> 1990-2009, Python Software Foundation.
      Last updated on Apr 15, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
    </div>
  </body>
</html>